{"ast":null,"code":"import _slicedToArray from \"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/slicedToArray.js\";\nimport classNames from 'classnames';\nimport * as React from 'react';\nfunction UnitNumber(_ref) {\n  var prefixCls = _ref.prefixCls,\n    value = _ref.value,\n    current = _ref.current,\n    _ref$offset = _ref.offset,\n    offset = _ref$offset === void 0 ? 0 : _ref$offset;\n  var style;\n  if (offset) {\n    style = {\n      position: 'absolute',\n      top: \"\".concat(offset, \"00%\"),\n      left: 0\n    };\n  }\n  return /*#__PURE__*/React.createElement(\"span\", {\n    style: style,\n    className: classNames(\"\".concat(prefixCls, \"-only-unit\"), {\n      current: current\n    })\n  }, value);\n}\nfunction getOffset(start, end, unit) {\n  var index = start;\n  var offset = 0;\n  while ((index + 10) % 10 !== end) {\n    index += unit;\n    offset += unit;\n  }\n  return offset;\n}\nexport default function SingleNumber(props) {\n  var prefixCls = props.prefixCls,\n    originCount = props.count,\n    originValue = props.value;\n  var value = Number(originValue);\n  var count = Math.abs(originCount);\n  var _React$useState = React.useState(value),\n    _React$useState2 = _slicedToArray(_React$useState, 2),\n    prevValue = _React$useState2[0],\n    setPrevValue = _React$useState2[1];\n  var _React$useState3 = React.useState(count),\n    _React$useState4 = _slicedToArray(_React$useState3, 2),\n    prevCount = _React$useState4[0],\n    setPrevCount = _React$useState4[1];\n  // ============================= Events =============================\n  var onTransitionEnd = function onTransitionEnd() {\n    setPrevValue(value);\n    setPrevCount(count);\n  };\n  // Fallback if transition event not support\n  React.useEffect(function () {\n    var timeout = setTimeout(function () {\n      onTransitionEnd();\n    }, 1000);\n    return function () {\n      clearTimeout(timeout);\n    };\n  }, [value]);\n  // ============================= Render =============================\n  // Render unit list\n  var unitNodes;\n  var offsetStyle;\n  if (prevValue === value || Number.isNaN(value) || Number.isNaN(prevValue)) {\n    // Nothing to change\n    unitNodes = [/*#__PURE__*/React.createElement(UnitNumber, Object.assign({}, props, {\n      key: value,\n      current: true\n    }))];\n    offsetStyle = {\n      transition: 'none'\n    };\n  } else {\n    unitNodes = [];\n    // Fill basic number units\n    var end = value + 10;\n    var unitNumberList = [];\n    for (var index = value; index <= end; index += 1) {\n      unitNumberList.push(index);\n    }\n    // Fill with number unit nodes\n    var prevIndex = unitNumberList.findIndex(function (n) {\n      return n % 10 === prevValue;\n    });\n    unitNodes = unitNumberList.map(function (n, index) {\n      var singleUnit = n % 10;\n      return /*#__PURE__*/React.createElement(UnitNumber, Object.assign({}, props, {\n        key: n,\n        value: singleUnit,\n        offset: index - prevIndex,\n        current: index === prevIndex\n      }));\n    });\n    // Calculate container offset value\n    var unit = prevCount < count ? 1 : -1;\n    offsetStyle = {\n      transform: \"translateY(\".concat(-getOffset(prevValue, value, unit), \"00%)\")\n    };\n  }\n  return /*#__PURE__*/React.createElement(\"span\", {\n    className: \"\".concat(prefixCls, \"-only\"),\n    style: offsetStyle,\n    onTransitionEnd: onTransitionEnd\n  }, unitNodes);\n}","map":{"version":3,"names":["classNames","React","UnitNumber","_ref","prefixCls","value","current","offset","style","position","top","left","createElement","className","getOffset","start","end","unit","index","SingleNumber","props","originCount","count","originValue","Number","Math","abs","useState","prevValue","setPrevValue","prevCount","setPrevCount","onTransitionEnd","useEffect","timeout","setTimeout","clearTimeout","unitNodes","offsetStyle","isNaN","Object","assign","key","transition","unitNumberList","push","prevIndex","findIndex","n","map","singleUnit","transform"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/antd/es/badge/SingleNumber.js"],"sourcesContent":["import classNames from 'classnames';\nimport * as React from 'react';\nfunction UnitNumber(_ref) {\n  let {\n    prefixCls,\n    value,\n    current,\n    offset = 0\n  } = _ref;\n  let style;\n  if (offset) {\n    style = {\n      position: 'absolute',\n      top: `${offset}00%`,\n      left: 0\n    };\n  }\n  return /*#__PURE__*/React.createElement(\"span\", {\n    style: style,\n    className: classNames(`${prefixCls}-only-unit`, {\n      current\n    })\n  }, value);\n}\nfunction getOffset(start, end, unit) {\n  let index = start;\n  let offset = 0;\n  while ((index + 10) % 10 !== end) {\n    index += unit;\n    offset += unit;\n  }\n  return offset;\n}\nexport default function SingleNumber(props) {\n  const {\n    prefixCls,\n    count: originCount,\n    value: originValue\n  } = props;\n  const value = Number(originValue);\n  const count = Math.abs(originCount);\n  const [prevValue, setPrevValue] = React.useState(value);\n  const [prevCount, setPrevCount] = React.useState(count);\n  // ============================= Events =============================\n  const onTransitionEnd = () => {\n    setPrevValue(value);\n    setPrevCount(count);\n  };\n  // Fallback if transition event not support\n  React.useEffect(() => {\n    const timeout = setTimeout(() => {\n      onTransitionEnd();\n    }, 1000);\n    return () => {\n      clearTimeout(timeout);\n    };\n  }, [value]);\n  // ============================= Render =============================\n  // Render unit list\n  let unitNodes;\n  let offsetStyle;\n  if (prevValue === value || Number.isNaN(value) || Number.isNaN(prevValue)) {\n    // Nothing to change\n    unitNodes = [/*#__PURE__*/React.createElement(UnitNumber, Object.assign({}, props, {\n      key: value,\n      current: true\n    }))];\n    offsetStyle = {\n      transition: 'none'\n    };\n  } else {\n    unitNodes = [];\n    // Fill basic number units\n    const end = value + 10;\n    const unitNumberList = [];\n    for (let index = value; index <= end; index += 1) {\n      unitNumberList.push(index);\n    }\n    // Fill with number unit nodes\n    const prevIndex = unitNumberList.findIndex(n => n % 10 === prevValue);\n    unitNodes = unitNumberList.map((n, index) => {\n      const singleUnit = n % 10;\n      return /*#__PURE__*/React.createElement(UnitNumber, Object.assign({}, props, {\n        key: n,\n        value: singleUnit,\n        offset: index - prevIndex,\n        current: index === prevIndex\n      }));\n    });\n    // Calculate container offset value\n    const unit = prevCount < count ? 1 : -1;\n    offsetStyle = {\n      transform: `translateY(${-getOffset(prevValue, value, unit)}00%)`\n    };\n  }\n  return /*#__PURE__*/React.createElement(\"span\", {\n    className: `${prefixCls}-only`,\n    style: offsetStyle,\n    onTransitionEnd: onTransitionEnd\n  }, unitNodes);\n}"],"mappings":";AAAA,OAAOA,UAAU,MAAM,YAAY;AACnC,OAAO,KAAKC,KAAK,M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